#pragma once
#include "CWindow/CDialogBase.h"
#include "Win32Utils/CIniHelperEx.h"
#include "Common.h"
#include "CMessageDialog.h"
#include "CAboutDialog.h"
#include <vector>
#include <functional>
#include <thread>

class CDialogSplit :
	public CDialogBase
{
public:

    CDialogSplit();
    ~CDialogSplit();

protected:

    dlg_msg LRESULT OnInitDialog(WPARAM wParam, LPARAM lParam);
	dlg_msg LRESULT OnClose(WPARAM wParam, LPARAM lParam);
    dlg_msg LRESULT OnLanguageChange(WPARAM wParam, LPARAM lParam);
    dlg_msg LRESULT OnDropFiles(WPARAM wParam, LPARAM lParam);
    dlg_msg LRESULT OnColor(WPARAM wParam, LPARAM lParam);
    dlg_msg LRESULT OnTaskBarCreated(WPARAM wParam, LPARAM lParam);
    dlg_command LRESULT OnTrayIcon(WPARAM wParam, LPARAM lParam);
    dlg_command LRESULT OnOutIndexHex(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnOpenFile(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnSaveDir(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnLang_zh_cn(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnLang_en_US(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnExit(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnTopmost(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnShow(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnHide(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnAbout(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnPreviewName(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnSplitFile(WORD wNotify, WORD wID, HWND hWnd);
    dlg_command LRESULT OnSplitHelp(WORD wNotify, WORD wID, HWND hWnd);
    dlg_notify LRESULT OnDeltaPos(WORD wID, LPNMHDR pNmhdr);

public:

    virtual BOOL DialogMessage(LPMSG pMsg);
    virtual BOOL PreTranslateMessage(LPMSG pMsg);

private:
    void ShowTrayIcon();
    void DeleteTrayIcon();
    VOID CreatePopMenu(int xPos, int yPos, bool isTop);
    bool ShowForeground(HWND hWnd);
    bool PreViewFileHeader(const _tstring strFile);
    bool PreViewName();
    void UpdateFileInfo();
    void UpdateOutInfo();
    bool SplitFile();

private:
    HMENU m_hPopMenu = NULL;
    HMENU m_hMainMenu = NULL;
    HWND m_hHideWnd = NULL;
    HBRUSH m_hBrush = NULL;

    LANGID m_langID = 0;

    bool m_bCancel = false;
    bool m_bTaskRunning = false;
    bool m_bQuit = false;

    CMessageDialog m_msgDlg;
    CMessageDialog m_helpDlg;
    CAboutDialog m_aboutDlg;

    std::thread m_splitTask;
	DECLARE_DLG_MESSAGE_MAP()
};